// pages/xqfb/xqfb.js
const app = getApp()

Page({
    data: {
        index: null,
        picker: ['学习', '趣闻', '要事'],
        imgList: [],
        circleimage: [],
        circletype: '',
        circlrtext: '',
        tt: ''
    },
    textareaBInput(e) {
        this.setData({
          textareaBValue: e.detail.value,
          circlrtext: e.detail.value
        })
      },
    PickerChange(e) {
        console.log(e);
        this.setData({
          index: e.detail.value,
          circletype: e.detail.value
        })
      },
      ChooseImage() {
        wx.chooseImage({
            count: 1, //默认9
            sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
            sourceType: ['album','camera'],
            success : (res) => {
              const tempFilePaths = res.tempFilePaths
              wx.uploadFile({
                url: 'https://www.woodymidnight.cn/BCUHelper/api/file/uploadFile', //仅为示例，非真实的接口地址
                filePath: tempFilePaths[0],
                name: 'file',
                success: (res) => {
                    console.log(res);
                    res = JSON.parse(res.data)
                    this.data.imgList.push(res.data.fileUrl)
                    this.data.circleimage.push(res.data.fileUrl)
                    this.setData({
                        imgList: this.data.imgList,
                        circleimage: this.data.circleimage
                    })
                  }
              })
            }
          })
      },
      ViewImage(e) {
        wx.previewImage({
          urls: this.data.imgList,
          current: e.currentTarget.dataset.url
        });
      },
      fabuqz:function(){
        var that = this;
        if(this.data.circletype == '' || this.data.circletext == ''){
          wx.showToast({
            title: '请完善信息',
            icon: 'error'
          })
        }else{
          wx.request({
            url: 'https://www.woodymidnight.cn/BCUHelper/api/circle/insertcircle',  
            method: 'POST',
            data:{
              circletype : this.data.circletype,
              circletext : this.data.circlrtext,
              circleimage : this.data.circleimage[0],
              userid : app.data.userInfo.userid,
              userimage : app.data.userInfo.userimage,
              username : app.data.userInfo.username
            },                                      
            header: { 'content-type': 'application/x-www-form-urlencoded' },
            success: function(res) { 
              that.setData({
                tt: res.data
              })
              console.log(res.data);
              wx.navigateBack({
                delta: 1,
              })
            },
            fail: function(res) {
              console.log("失败");
            }
          })
        }
      },
    onLoad: function (options) {
    },


    onReady: function () {

    },

    onShow: function () {

    },


    onHide: function () {

    },


    onUnload: function () {

    },


    onPullDownRefresh: function () {

    },


    onReachBottom: function () {

    },


    onShareAppMessage: function () {

    }
})